<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:c="http://xmlns.jcp.org/jsf/composite"
	xmlns:p="http://primefaces.org/ui">

<ui:decorate template="/jsp/WEB/pageLayout.xhtml">
	<ui:define name="centro">

		<h:form id="form">

			<p:panel header="Dados Para Busca">
				<p:messages id="messages" showDetail="true" autoUpdate="true"
					closable="true" />
				<!-- script para o calendário BR -->

				<h:panelGrid id="gridRel" columns="10"
					style="border:0px;margin-top:1%;">




					<p:outputLabel for="date" value="Data inicial:" />
					<p:calendar id="date" value="#{RelatorioCardPedBean.dateIni}"
						pattern="dd/MM/yyyy" locale="pt_BR"
						title="Campo obrigatório. Informe a data inicial" />

					<h:outputScript name="calendario_pt_BR.js" library="js" />
					<p:outputLabel for="datefim" value="Data final:" />
					<p:calendar id="datefim" value="#{RelatorioCardPedBean.dateFim}"
						pattern="dd/MM/yyyy" locale="pt_BR"
						title="Campo obrigatório. Informe a data final" />

					<h:outputLabel value="Nº cartão" />
					<p:inputText id="nome" value="#{RelatorioCardPedBean.consulta}" />

					<p:commandButton id="searchButton" image="ui-icon-search"
						update="@all" ajax="false" title="Consultar Cartão e situação"
						actionListener="#{RelatorioCardPedBean.exibirRelatorio}" />
				</h:panelGrid>


				<p:dataTable id="table1" var="relatorio"
					value="#{RelatorioCardPedBean.rel}" rowIndexVar="rowIndex"
					emptyMessage="Nenhum registro encontrado"
					style="position: auto;margin-top:40px" paginator="true" rows="20"
					rowsPerPageTemplate="10,20,30,40,50">

					<p:column sortBy="idPedido" style="text-align:center;width:10px"
						headerText="Nº Pedido">
						<h:outputText value="#{relatorio.idPedido}" />
					</p:column>

					<p:column sortBy="numCard" style="text-align:center"
						headerText="Nº Cartão">
						<h:outputText value="#{relatorio.numCard}" />
					</p:column>

					<p:column sortBy="valorCredito" style="text-align:center"
						headerText="Saldo Cartão">
						<h:outputText value="#{relatorio.valorCredito}" >
						<f:convertNumber type="currency" currencySymbol="R$" />
						</h:outputText>
					</p:column>
					
					<p:column sortBy="dataPedido" style="text-align:center"
						headerText="Data Pedido">
						<h:outputText value="#{relatorio.dataPedido}">
							<f:convertDateTime locale="pt_BR" pattern="dd/MM/yyyy" />
						</h:outputText>
					</p:column>

					<p:column sortBy="horaPedido" style="text-align:center"
						headerText="Hora Pedido">
						<h:outputText value="#{relatorio.horaPedido}" />
					</p:column>


					<p:column sortBy="statusPedido" style="text-align:center"
						headerText="Ped. Finalizado">
						<h:outputText value="Sim" rendered="#{relatorio.statusPedido}" />
						<h:outputText value="Não" rendered="#{not relatorio.statusPedido}" />
					</p:column>

					<p:column sortBy="dataFechamento" style="text-align:center"
						headerText="Data Fechamento Ped.">
						<h:outputText value="#{relatatorio.dataFechamento}">
							<f:convertDateTime locale="pt_BR" pattern="dd/MM/yyyy" />
						</h:outputText>
					</p:column>

					<p:column sortBy="horaFechamento" style="text-align:center"
						headerText="Hora Fechamento Ped.">
						<h:outputText value="#{rel.horaFechamento}" />
					</p:column>


					<p:column style="width: 30px;">
						<p:commandButton update=":form1"
							title="Exibir detalhamento de pedido"
							oncomplete="PF('detalhaDialog').show()" icon="ui-icon-arrow-4"
							action="#{RelatorioCardPedBean.selecionaDetail}">
							<f:setPropertyActionListener value="#{relatorio.idPedido}"
								target="#{RelatorioCardPedBean.idPedido}" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>
		</h:form>



		<!-- ************************************************************************ -->
		<!-- ** Dialog para detalhamento **-->
		<!--*********************************************************************** -->

		<h:form id="form1">
			<p:dialog id="detalhaDlg" widgetVar="detalhaDialog" resizable="false"
				showEffect="fade" hideEffect="explode" style="margin-top:3%"
				header="Informações de itens do pedido #{relatorio.idPedido}">

				<p:dataTable id="table1" var="relDetail"
					value="#{RelatorioCardPedBean.relDetail}" rowIndexVar="rowIndex"
					emptyMessage="Nenhum registro encontrado"
					style="position: auto;margin-top:2%" paginator="true" rows="8"
					rowsPerPageTemplate="10,20,30,40,50">

					<p:column style="width:25px" headerText="Produto">
						<h:outputText value="#{relDetail.descMerc}" />
					</p:column>

					<p:column style="text-align:center;width:4px"
						headerText="Preço Unit. R$">
						<h:outputText value="#{relDetail.valorUnit}" >
						<f:convertNumber type="currency" currencySymbol="$" />
						</h:outputText>
					</p:column>

					<p:column style="text-align:center;width:4px" headerText="Total R$"
						filterMatchMode="contains">
						<h:outputText value="#{relDetail.valorTotal}" >
						<f:convertNumber type="currency"/>
						</h:outputText>
					</p:column>

				</p:dataTable>


			</p:dialog>
		</h:form>



	</ui:define>
</ui:decorate>
</html>

